//
//  HMVisitorTableViewController.swift
//  swift-新浪微博0
//
//  Created by 赵玉忠 on 16/8/30.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMVisitorTableViewController: UITableViewController,HMVisitorViewDelegate{
    
    // 代表当前用户的登录状态
    var userLogin = HMUserAccountViewModel.sharedModel.userLogon
    
    // 在loadView里面根据是否登录去选择加载不同的view
    override func loadView() {
        if userLogin {
            super.loadView()
        }else{
            // 加载自己的View
            setupVisitorView()
        }
    }
    
    func setupVisitorView() {
        let v = self.visitorView
        self.view = v
        // 设置左右登录注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: nil)
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: nil, action: #selector(visitorViewWillLogin))
        
        // 直接将讲属性抛出也是可以的
        visitorView.loginButton.addTarget(self, action: #selector(visitorViewWillLogin), for: UIControlEvents.touchUpInside)
    }
    
    
    // MARK: - 懒加载控件
    lazy var visitorView: HMVisitorView = {
        let visitorView = HMVisitorView()
        return visitorView
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    
    @objc private func registerButtonClick() {
        print("注册")
    }
    
    // MARK: - HMVisitorViewDelegate
    
    func visitorViewWillLogin() {
        
        // 初始化一个导航控制器
        let vc = HMNavigationController(rootViewController: HMOAuthViewController())
        // moda控制器
        present(vc, animated: true, completion: nil)
    }
}


